package com.wutianyi;

import java.util.HashMap;
import java.util.Map;

public class Example
{
    private Map<Class<?>, Object> favorites = new HashMap<Class<?>, Object>();

    public <T> void setFavorite(Class<T> klass, T thing)
    {
        favorites.put(klass, thing);
    }

    public <T> T getFavorite(Class<T> klass)
    {
        return klass.cast(favorites.get(klass));
    }

    public static void main(String[] args)
    {
        Example e = new Example();
        e.setFavorite(String.class, "Java");
        e.setFavorite(Integer.class, 0xcafebabe);
        String s = e.getFavorite(String.class);
        int i = e.getFavorite(Integer.class);
    }
}
